import os

import yaml


def exists(val):
    return val is not None


def default(val, d):
    return val if exists(val) else d


def load_config(path: str) -> dict:
    with open(path, 'r') as f:
        config = yaml.load(f, Loader=yaml.FullLoader)
        return config


def set_environment(config: dict) -> None:
    os.environ['model'] = config['llm']['model']
    os.environ['api_key'] = default(config['llm']['api_key'], '')
    os.environ['base_url'] = default(config['llm']['endpoint'], '')
    os.environ['openai'] = default(config['llm']['openai'], 'openai')


if __name__ == '__main__':
    print(load_config("/Users/jan/Desktop/multi-agent/env.yaml"))
